#include "jTimer.h"

jTimer::jTimer()
{	
	SDL_Init(SDL_INIT_TIMER);

	m_ActualTicks  = 0 ;
	m_StopWatchCurrentTicks = 0;
	m_Pause1Ticks = 0;
	m_StopWatchTime = 0;
	m_Paused = false;

	m_Hours = 0;
	m_Mins = 0;
	m_Secounds = 0;
	m_Milliseconds = 0;
}

jTimer::~jTimer()
{
}

void jTimer::Reset()
{	
	m_ActualTicks  = 0 ;
	m_StopWatchCurrentTicks = 0;
	m_Pause1Ticks = 0;
	m_StopWatchTime = 0;
	m_Paused = false;

	m_Hours = 0;
	m_Mins = 0;
	m_Secounds = 0;
	m_Milliseconds = 0;
}

void jTimer::Start()
{
		m_StopWatchCurrentTicks = SDL_GetTicks();
}

void jTimer::Stop()
{
	//Get the current Ticks for when its stopped.
	m_StopWatchCurrentTicks += SDL_GetTicks();
	m_Paused = true;

	setStopWatchTime();
}

void jTimer::Resume()
{
	if(m_Paused)
	{
	//Get the time between the pause and the resume
	m_ActualTicks = SDL_GetTicks();
	m_Pause1Ticks += m_ActualTicks - m_StopWatchCurrentTicks;
	m_Paused = false;

	setStopWatchTime();
	}
}


void jTimer::setStopWatchTime()
{
	if(!(m_Paused))
		m_StopWatchTime = (SDL_GetTicks() -  m_Pause1Ticks) - m_StopWatchCurrentTicks;

}

int jTimer::getSeconds()
{
	//m_ActualTicks = SDL_GetTicks();
	setStopWatchTime();

	return m_StopWatchTime/1000;
}